array manipulation hackerrank solution